package codetop;

public class ReverseList {
    public ListNode reverseList(ListNode head) {
        if (head==null)return null;
        ListNode pre=null;
        while (head.next!=null){
            ListNode next=head.next;
            head.next=pre;
            pre=head;
            head=next;
        }
        head.next=pre;
        return head;
    }
}
